var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
var option;

const data = [];
data.push(Math.round(Math.random() * 2));
data.push(Math.round(Math.random() * 100));

option = {
  yAxis: {
    max: "dataMax",
    show: false,
  },
  xAxis: {
    type: "category",
    data: ["课程名称", "课程名称"],
    inverse: true,
    animationDuration: 300,
    animationDurationUpdate: 300,
    max: 0, // only the largest 3 bars will be displayed
    // show: false,
  },
  series: [
    {
      realtimeSort: true,
      type: "bar",
      data: data,
      label: {
        show: false,
        position: "top",
        valueAnimation: true,
      },
    },
  ],
  legend: {
    show: true,
  },
  animationDuration: 0,
  animationDurationUpdate: 3000,
  animationEasing: "linear",
  animationEasingUpdate: "linear",
};
function run() {
  for (var i = 0; i < data.length; ++i) {
    if (Math.random() > 0.9) {
      data[i] += Math.round(Math.random() * 200);
    } else {
      data[i] += Math.round(Math.random() * 20);
    }
  }
  myChart.setOption({
    series: [
      {
        type: "bar",
        data,
        itemStyle: {
          // color: "transparent",
          normal: {
            //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
            color: function (params) {
              var colorList = ["rgb(164,205,238)", "transparent"];
              return colorList[params.dataIndex];
            },
          },
        },
      },
    ],
  });
}
setTimeout(function () {
  run();
}, 0);
setInterval(function () {
  run();
}, 3000);


if (option && typeof option === "object") {
  myChart.setOption(option);
}

